<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>会员等级列表</title>
    <!--{include file="comm/icheck.tpl"}-->
</head>
<body>

<div class="container">

    <div class="comm_content">
        <table id="flex" style="display:none"></table>
    </div>

</div>

<div id="pop" style="display: none;">
<div style="width:100%;">

    <div class="container">

        <div class="comm_content">

            <div class="commAttr">
                <form id="cust_rank_Form" class="form-horizontal" name="cust_rank_Form" onsubmit="return false;">

                    <div class="form-group">
                        <label for="rankName" class="col-sm-3 control-label"><span class="red">*</span> 等级名称：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control w300" id="rankName" name="rankName" placeholder="请输入等级名称" value="" >
                        </div>
                        <input type="hidden" id="rankID" name="rankID" value="0">
                    </div>
                    <div class="form-group">
                        <label for="needAmt" class="col-sm-3 control-label"><span class="red">*</span> 累计消费金额：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control w300" id="needAmt" name="needAmt" placeholder="累计消费金额必须为大于等于0的整数" value="" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="rate" class="col-sm-3 control-label"><span class="red">*</span> 会员折扣：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control w300" id="rate" name="rate" placeholder="会员折扣必须为大于0，小于等于1的数字" value="" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="pointsRate" class="col-sm-3 control-label"><span class="red">*</span> 赠送积分倍数：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control w300" id="pointsRate" name="pointsRate" placeholder="赠送积分倍数必须为大于等于1的数字" value="" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"><span class="red">*</span> 是否免运费：</label>
                        <div class="col-sm-9">
                            <div class="fl" style="margin-right: 10px;">
                                <input type="radio" class="square-radio" id="freightFree-radio-0" name="freightFree" value="0" checked>
                                <label for="freightFree-radio-0">有运费</label>
                            </div>
                            <div class="fl">
                                <input type="radio" class="square-radio" id="freightFree-radio-1" name="freightFree" value="1" >
                                <label for="freightFree-radio-1">免运费</label>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</div>

<script type="text/javascript">

    $("#flex").flexigrid({
        url:"/invokingAjax-backend/customer/customerRank.ajax?operFlg=1",
        dataType: "json",
        colModel : [
            <!--{if $edit_permission}-->
            {display: "操作", width : 80, align: 'center'},
            <!--{/if}-->
            {display: "等级编号", name : "rankID" , align: 'center', width : 60 , sortable : true },
            {display: "等级名称", width : 200},
            {display: "累计消费金额", width : 150},
            {display: "会员折扣", width : 100},
            {display: "赠送积分倍数", width : 100},
            {display: "是否免运费", width : 80, align: 'center'},
        ],
        <!--{if $edit_permission}-->
        buttons : [
            {name: "添加", bclass: "add", onpress : "source.add"}
        ],
        <!--{/if}-->
        sortname: "rankID",
        sortorder: "asc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true
    });

    var source = {

        add: function( id ) {

            if (!id) {
                id = null;
            }

            //调用打开弹出层公共JS方法
            E.popup.open({
                id:"pop",   		 //获取id为"pop"元素内的HTML
                title: id == null ? "新增会员等级" : "修改会员等级",       //弹出层标题
                css: "width:800px;",     //设置弹出层样式
                btnName: "保存",         //执行“确定”操作的按钮名称
                btnCall:"source.check();"  //点击确定后执行的方法
            });

            $('.square-radio').iCheck({
                checkboxClass: 'icheckbox_square-blue',
                radioClass: 'iradio_square-blue',
                increaseArea: '20%' // optional
            });

            if (id) {

                E.ajax_get({
                    url: "/invokingAjax-backend/customer/customerRank.ajax?operFlg=2&rankID=" + id,
                    call: function( o ) {
                        if (o.code == 200) {
                            $("#rankID").val(o.data.rankID);
                            $("#rankName").val(o.data.rankName);
                            $("#needAmt").val(o.data.needAmt);
                            $("#rate").val(o.data.rate);
                            $("#pointsRate").val(o.data.pointsRate);
                            $('#freightFree-radio-'+o.data.freightFree).iCheck('check');
                        } else {
                            E.alert(o.message);
                        }
                    }
                });

            }

        },

        //验证获得收货地址相关数据
        check:function(){

            this.dt = E.getFormValues("cust_rank_Form");
            var err_msg = '';

            if (E.isEmpty(this.dt.rankName)) {
                err_msg += '等级名称不能为空，请填写<br />';
            }
            if (E.isEmpty(this.dt.needAmt)) {
                err_msg += '累计消费金额不能为空，请填写<br />';
            } else if (!E.isDigital(this.dt.needAmt) || this.dt.needAmt < 0) {
                err_msg += '累计消费金额必须为大于等于0的整数<br />';
            }
            if (E.isEmpty(this.dt.rate)) {
                err_msg += '会员折扣不能为空，请填写<br />';
            } else if(!E.isNum(this.dt.rate) || this.dt.rate > 1 || this.dt.rate <= 0) {
                err_msg += '会员折扣必须为大于0，小于等于1的数字<br />';
            }
            if (E.isEmpty(this.dt.pointsRate)) {
                err_msg += '赠送积分倍数不能为空，请填写<br />';
            } else if(!E.isNum(this.dt.pointsRate) || this.dt.pointsRate < 1) {
                err_msg += '赠送积分倍数必须为大于1的数字<br />';
            }

            if (err_msg != '') {
                E.alert(err_msg);
            } else {
                E.confirm('您确认要保存该会员等级信息吗？', function() {

                    E.loadding.open("正在保存，请稍候...");
                    E.ajax_post({
                        url: "/invokingAjax-backend/customer/customerRank.ajax?operFlg=100&act=edit",
                        data: source.dt,
                        call: function( o ) {
                            E.loadding.close();
                            if (o.code == 200) {
                                E.popup.close();
                                E.alert(o.message, 2, "source.load");
                            } else {
                                E.alert(o.message);
                            }
                        }
                    });

                });
            }

        },

        load: function(){
            $("#flex").flexReload();
        }

    };

</script>

</body>
</html>